/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sv.com.intesal.clases.abstracts;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import sv.com.intesal.clases.auxiliar.cVarios;
import sv.com.intesal.conexion.cConexion;

/**
 *
 * @author ejerez
 */
public class ControladorEncaAbstract {

    protected cVarios v;
    protected PreparedStatement ps_enca;
    protected PreparedStatement ps_deta;
    protected ResultSet rs_enca;
    protected ResultSet rs_deta;

    public ControladorEncaAbstract() {
        this.v = new cVarios();
        this.ps_enca = null;
        this.ps_enca = null;
        this.rs_enca = null;
        this.rs_deta = null;
    }

    public PreparedStatement setEncaPreparedStatement(String sql) throws Exception {
        try {
            return this.ps_enca = cConexion.conectar().prepareStatement(sql);
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void executeEncaUpdate() throws Exception {
        try {
            this.ps_enca.executeUpdate();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void executeDetaUpdate() throws Exception {
        try {
            this.ps_deta.executeUpdate();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public PreparedStatement setDetaPreparedStatement(String sql) throws Exception {
        try {
            return this.ps_deta = cConexion.conectar().prepareStatement(sql);
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void getEncaExecuteQuery(String sql) throws Exception {
        try {
            this.rs_enca = cConexion.conectar().prepareStatement(sql).executeQuery();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void getDetaExecuteQuery(String sql) throws Exception {
        try {
            this.rs_deta = cConexion.conectar().prepareStatement(sql).executeQuery();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void getEncaExecuteQuery(PreparedStatement ps) throws Exception {
        try {
            this.rs_enca = ps_enca.executeQuery();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void getDetaExecuteQuery(PreparedStatement ps) throws Exception {
        try {
            this.rs_deta = ps_deta.executeQuery();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void setCloseConexion() throws Exception {
        try {
            if (ps_enca != null) {
                this.ps_enca.close();
            }
            if (ps_deta != null) {
                this.ps_deta.close();
            }
            if (rs_enca != null) {
                this.rs_enca.close();
            }
            if (rs_deta != null) {
                this.rs_deta.close();
            }
        } catch (Exception e) {
            throw new Exception(e);
        }
    }
}
